<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use DB;

class AdminController extends Controller
{

    public function showLogin(){
        return view("Admin/login");
    }

    public function showAddForm()
    {
        return view("Admin/article-add");

    }

    public function addArticle(Request $request)
    {
        $insertData['article_title'] = $request->input("articletitle");
        $insertData['article_content'] = $request->input("editorValue");
        $insertData['article_author'] = $request->input("author");
        $insertData['article_create_at'] = date('Y-m-d H:i:s');
        $insertData['article_is_publish'] = 1;
        $result = DB::table("article")
            ->insert($insertData);
        if ($result) {
            dd("插入成功");
        }else{
            dd('插入失败');
        }
    }

    public function mangerAllArticle()
    {
        $data = DB::table("article")
            ->get();
        return view("Admin/article-list")->with("articles",$data);
    }


    public function adminLogin(Request $request)
    {
        $rule['admin_name'] = $request->input("adminName");
        $rule['admin_password'] = md5($request->input("adminPassword"));
        $result = DB::table("admin")
            ->where($rule)
            ->first();
        if (is_null($result)){
            dd("登录失败");
        }else{
            return redirect("/admin/index");
        }
    }


    //
}
